package risk.control.project.utils;

import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant;

public class TimeUtils {

    //计算时间差
    public static long calculate(long timestamp1, long timestamp2) {
        // 将时间戳转换为Instant对象
        Instant instant1 = Instant.ofEpochMilli(timestamp1);
        Instant instant2 = Instant.ofEpochMilli(timestamp2);
        // 计算时间差并返回结果（单位：毫秒）
        Duration duration = Duration.between(instant1, instant2);
        return duration.toMillis();
    }

    //获取当前时间
    public static String getCurrentTime() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis());
    }
}
